package com.sinothk.software.utils;

import ohos.agp.components.SlideDrawer;
import ohos.app.Context;

public class XUtils {

    private static Context context;

    public static void init(Context mContext) {
        context = mContext;
    }

    private static void contextNullError() {
        throw new NullPointerException("mContext为null, 请在调用前初始化：XUtils.init(context)");
    }

    private static StringUtil stringUtil;

    public static StringUtil string() {
        if (stringUtil == null) {
            synchronized (XUtils.class) {
                stringUtil = new StringUtil();
            }
        }
        return stringUtil;
    }

    /**
     * 时间工具类
     */
    private static DateUtil dateUtil;

    public static DateUtil date() {
        if (dateUtil == null) {
            synchronized (XUtils.class) {
                dateUtil = new DateUtil();
            }
        }
        return dateUtil;
    }

    /**
     * Toast
     */
    private static ToastUtil toastUtil;

    public static ToastUtil toast() {
        if (toastUtil == null) {
            synchronized (XUtils.class) {
                if (context == null) {
                    contextNullError();
                }

                toastUtil = new ToastUtil(context);
            }
        }
        return toastUtil;
    }

    /**
     * Intent
     */
    private static IntentUtil intentUtil;

    public static IntentUtil intent() {
        if (intentUtil == null) {
            synchronized (XUtils.class) {
                intentUtil = new IntentUtil();
            }
        }
        return intentUtil;
    }
}
